Class Sound
static var newId=1;
static var items=[];
public static function init(path){
	if(path.indexOf("http")!=0) path="res/sound/"+path;
	var audio;
	for(var i=0;i<Me.items.length;i++){
		var audio2=Me.items[i];
		if(!audio2.playing&&audio2.path==path){
			audio=audio2;
			break;
		}
	}
	if(!audio){
		audio=document.createElement("audio");
		var isSupport=audio.play!=null;
		if(G.isMobile&&!G.isWx) isSupport=false;
		if(!isSupport){
			return;
		}
		audio.src=path;
		Me.items.push(audio);
		audio.path=path;
	}
	audio.id=Me.newId;
	Me.newId++;
	audio.load();
	return audio.id;
}
public static function play(id,doEnd){
	var audio=Me.getAudio(id);
	if(!audio) return;
	audio.doEnd=doEnd;
	audio.onended=Me.onEnd;
	audio.playing=true;
	audio.play();
}
public static function stop(id){
	var audio=Me.getAudio(id);
	if(!audio) return;
	audio.playing=false;
	audio.pause();
	audio.currentTime=0;
}
public static function isPlaying(id){
	var audio=Me.getAudio(id);
	if(!audio) return;
	return audio.playing;
}
public static function getCurrentTime(id){
	var audio=Me.getAudio(id);
	if(!audio) return;
	return audio.currentTime;
}
public static function getDuration(id){
	var audio=Me.getAudio(id);
	if(!audio) return;
	return audio.duration;
}
public static function getAudio(id) {
	var audio;
	for(var i=0;i<Me.items.length;i++){
		var audio2=Me.items[i];
		if(audio2.id==id){
			audio=audio2;
		}
	}
	return audio;
}
public static function pauseAll(){
	for(var i=0;i<Me.items.length;i++){
		var audio=Me.items[i];
		if(!audio.playing) continue;
		audio.pause();
	}
}
public static function resumeAll(){
	for(var i=0;i<Me.items.length;i++){
		var audio=Me.items[i];
		if(!audio.playing) continue;
		audio.play();
	}
}
static function onEnd(evt){
	var audio=evt.target;
	audio.playing=false;
	if(audio.doEnd==true){
		Sound.play(audio.path,true);
	}
	else{
		call(audio.doEnd);
	}
}